|
|
|
|
|
|
|
Learn how to use the Forms collection |
|
|
|
|
|
|
|
|
Learn how to manipulate the Controls collection |
|
|
|
|
|
|
|
|
Learn how to build your own collections |
|
|
|
|
|
|
|
|
Learn how to wrap your collections into a collection class |
|
|
|
|
|
|
|
|
Sample Project File: \Chapter22\Collections.vbp |
|
|
|
|
|
|
|
|
As mentioned earlier, a collection is basically an array on steroids. Collections are different than arrays, but they act very much the same in that you have lists of items grouped under a common name. Collections are a lot more powerful than arrays, however, in that they have properties and methods attached to them. These properties and methods allow you to add new items very easily, delete items, and even insert items into a specific location. All these characteristics, plus a few more, make collections a lot easier to utilize than arrays. |
|
|
|
|
|
|
|
|
Visual Basic allows for a few different types of collectionsthose that Visual Basic creates automatically, those that you create yourself, and those that are created as a part of ActiveX controls. |
|
|
|
|
|
|
|
|
Examples of Built-in Collections |
|
|
|
|
|
|
|
|
Visual Basic maintains a global collection of all the forms that have been loaded at runtime in a collection called Forms. Visual Basic also maintains a collection of all the loaded controls for each active form in a collection called Controls. Theres also a Printers collection that reports to you all the printers connected to your system. Youll learn to manipulate these built-in collections first; later youll learn to create your own collections. |
|
|
|
|
|
|
|
|
Characteristics of the Built-in Collections |
|
|
|
|
|
|
|
|
Collections have several attributes that you need to be aware of to use. Lets learn about some of these: |
|
|
|
|
|
|
|
|
The Visual Basic collections are never declared because theyre global. |
|
|
|
|
|
|
|
|
You never pass the built-in collections to a procedure because theyre global and dont have to be passed. |
|
|
|
|
|